package com.awenhui.demo.dao;

import com.awenhui.demo.model.entity.UaUserEntity;
import com.awenhui.demo.model.entity.UserEntity;
import com.awenhui.demo.model.rbac.AddUserModel;
import com.awenhui.demo.model.rbac.UserModel;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/**
 * 注解版查询
 */
public interface UserAnnotationMapper {

    @Insert("insert into ua_user(user_id,username,password,email,mobile,state) values(#{userId},#{username},#{password},#{email},#{mobile},1)")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    int addUser(AddUserModel model);


    @Delete("delete from ua_user where user_id=#{id}")
    int deleteUser(Long id);

    @Update("update ua_user set username=#{username},password=#{password},email=#{email},mobile=#{mobile} where user_id=#{userId}")
    int updateUser(AddUserModel model);

    @Select("select * from ua_user   where user_id=#{id}")
    UserModel getUser(Long id);

    @Select("select * from ua_user ")
    List<UserEntity> getUsers();

    @Select("select * from ua_user where user_id=#{id}")
    @Results({
            @Result(id=true/*返回主键*/,property = "dept",column = "dept_id",one =@One(fetchType = FetchType.LAZY,select = "com.awenhui.demo.dao.DeptMapper.getDeptById"))
    })
    UaUserEntity getUserById(Long id);

}
